
package de.justphil.tcg.tcgandroidclient.util;

import android.util.Base64;

import com.twmacinta.util.MD5;

public class Authorization {
	
	public static String getAuthorization(String user, String pwd) {
	
		// String $username, $password
		// String $authValue = base64( $username + ":" + md5( $password ) )
		// Potential base64/md5 byte-to-string/string-to-byte conversions are UTF-8 based.
		// The HTTP request must include an "Authorization" header with value $authValue.
		try {
			MD5 md5 = new MD5();
			md5.Update(pwd);
			String encodedPwd = md5.asHex();
			String temp = user + ":" + encodedPwd;
			String authorization =
					new String(Base64.encodeToString(temp.getBytes("UTF-8"), Base64.NO_WRAP));
			return authorization;
		}
		catch (Exception e) {
			throw new RuntimeException("Authorization encoding does not work: " + e.getMessage());
		}
	}
}
